/*登录页*/
const inputs = document.querySelectorAll("input");
const inbutton = document.querySelector(".inbutton");
const zhu = document.querySelector(".zhu");
const deng = document.querySelector(".deng");
const outer = document.querySelector(".outer");

/*可滑动页*/
const button4 = document.querySelector(".button4");
const button5 = document.querySelector(".button5");
const counter = document.querySelector(".counter");
const wenzi2 =  document.querySelector(".wenzi2");

console.log(localStorage.getItem("token"));

zhu.addEventListener("click",()=>{
    
    inbutton.addEventListener("click",()=>{
    axios({
        method:"POST",
        baseURL:"http://49.235.224.185:8000",
        url:"/users",
        data:{
            "name":inputs[0].value,
            "password":inputs[1].value,
        },
        
    })
    .then((res)=>{
        localStorage.setItem("token",res.data.token);
        alert("注册成功~~");
        outer.setAttribute("style","display:none");
        console.log(res);
       
      
    })
    .then((res)=>{
        console.log(localStorage.getItem("token"));
    })
    .catch((err)=>{
        console.log(err.data);
    })
    
});
})
deng.addEventListener("click",()=>{
    inbutton.addEventListener("click",()=>{
    axios({
        method:"POST",
        baseURL:"http://49.235.224.185:8000",
        url:"/login",
        data:{
            name:inputs[0].value,
            password:inputs[1].value
        },
        
    })
    .then((res)=>{
        localStorage.setItem("token",res.data.token);
        console.log(res);
        alert("登录成功~~");
        outer.setAttribute("style","display:none");

    })
    .catch((err)=>{
        console.log(err.data);
    })
});
})
/*查看所有动态*/
wenzi2.addEventListener("click",()=>{
    axios({ 
     method:"GET",
     baseURL:"http://49.235.224.185:8000",
     url:"/moment",
     headers:{
          Authorization:localStorage.getItem("token")
     },
})
.then((res)=>{
     console.log(res);
     })
})
    


  






